package com.linewow.xhyy.hrxb;

import android.content.Context;
import android.content.Intent;
import com.linewow.xhyy.nihaonew.activity.account.LoginActivity;
import com.linewow.xhyy.nihaonew.application.NiHaoApp;
import com.linewow.xhyy.nihaonew.db.NiHaoHelper;
import com.linewow.xhyy.nihaonew.event.MessageEvent;

import org.simple.eventbus.EventBus;

public class DemoHelper {

    protected static final String TAG = "DemoHelper";


    /**
     * EMEventListener
     */

    private static DemoHelper instance = null;


    /**
     * sync groups status listener
     */

    private Context appContext;


    private DemoHelper() {
    }

    public synchronized static DemoHelper getInstance() {
        if (instance == null) {
            instance = new DemoHelper();
        }
        return instance;
    }

    /**
     * init helper
     *
     * @param context application context
     */
    public void init(Context context) {
        appContext = context;

        //debug mode, you'd better set it to false, if you want release your App officially.

    }


    public void logoutUpdate() {
        NiHaoHelper.getInstance().logOut();
        ((NiHaoApp) (appContext)).resumeData();
        EventBus.getDefault().post(new MessageEvent("logout"), "logout");

    }


    /**
     * group change listener
     */


    /**
     * user has logged into another device
     */
    public void onConnectionConflict() {
        Intent intent = new Intent(appContext, LoginActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(Constant.ACCOUNT_CONFLICT, true);
        appContext.startActivity(intent);
    }


}